package com.fan.websocketstudy.controller;

import cn.hutool.core.bean.BeanUtil;
import com.fan.websocketstudy.dto.UserDTO;
import com.fan.websocketstudy.entity.User;
import com.fan.websocketstudy.service.TestService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: fan
 * @CreateTime 2024/6/1 22:09
 * @Description
 * @Version 1.0
 */
@RestController
@RequestMapping("/test")
@Tag(name = "测试", description = "测试API")
public class TestController {

    @Resource
    private TestService testService;


    @Operation(summary = "查询", description = "查询信息")
    @GetMapping("/getInfo")
    public ResponseEntity<List<String>> getAllMessages() {


        List<String> message = List.of("Hello", "World");

        return new ResponseEntity<>(message, HttpStatus.OK);
    }


    @Operation(summary = "添加", description = "添加数据")
    @PostMapping("/addInfo")
    public ResponseEntity<String> addMessage(@RequestBody UserDTO testDTO) {

        User test = BeanUtil.toBean(testDTO, User.class);

        testService.save(test);

        return new ResponseEntity<>("Message added successfully", HttpStatus.OK);
    }

}
